#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
核心接口定义

定义应用中服务和仓储层的基础接口，遵循依赖倒置原则
"""

from abc import ABC, abstractmethod
from typing import Any, Dict, List, Optional, TypeVar, Generic

T = TypeVar('T')  # 泛型类型


class Repository(Generic[T], ABC):
    """仓储基础接口"""
    
    @abstractmethod
    def get_by_id(self, id: str) -> Optional[T]:
        """根据ID获取实体"""
        pass
    
    @abstractmethod
    def list(self, filters: Dict[str, Any] = None, page: int = 1, size: int = 10) -> List[T]:
        """获取实体列表"""
        pass
    
    @abstractmethod
    def create(self, entity: T) -> T:
        """创建实体"""
        pass
    
    @abstractmethod
    def update(self, entity: T) -> T:
        """更新实体"""
        pass
    
    @abstractmethod
    def delete(self, id: str) -> bool:
        """删除实体"""
        pass


class Service(Generic[T], ABC):
    """服务基础接口"""
    
    @abstractmethod
    def get_by_id(self, id: str) -> Optional[T]:
        """根据ID获取实体"""
        pass
    
    @abstractmethod
    def list(self, filters: Dict[str, Any] = None, page: int = 1, size: int = 10) -> List[T]:
        """获取实体列表"""
        pass
    
    @abstractmethod
    def create(self, data: Dict[str, Any]) -> T:
        """创建实体"""
        pass
    
    @abstractmethod
    def update(self, id: str, data: Dict[str, Any]) -> T:
        """更新实体"""
        pass
    
    @abstractmethod
    def delete(self, id: str) -> bool:
        """删除实体"""
        pass 